package servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 13-请求参数中文乱码问题
 * ①先编码(iso8859-1)，再解码(utf-8)
 */
@WebServlet("/demo18")
public class Demo18Servlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        //先编码(iso8859-1)
        byte[] bys = username.getBytes("iso8859-1");
        //再解码(utf-8)
        username = new String(bys,"utf-8");

        System.out.println("username = " + username);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
